<template>
  <div class="app-container">
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <!-- <el-input
            v-model="query.blurry"
            clearable
            size="small"
            placeholder="请输入关键词"
            style="width: 200px;"
            class="filter-item"
            @keyup.enter.native="crud.toQuery"
          /> -->
        <!-- <date-range-picker v-model="query.createTime" class="date-item" /> -->
        <!-- <el-select
              v-model="query.enabled"
              clearable
              size="small"
              placeholder="状态"
              class="filter-item"
              style="width: 90px"
              @change="crud.toQuery"
            >
              <el-option
                v-for="item in enabledTypeOptions"
                :key="item.key"
                :label="item.display_name"
                :value="item.key"
              />
            </el-select> -->
        <!-- <rrOperation /> -->
      </div>
      <div class="btnContain">
        <el-button @click="addPaint">新建</el-button>
      </div>
    </div>
    <!--表格渲染-->
    <el-table ref="table" v-loading="crud.loading" :height="height" border :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <el-table-column :show-overflow-tooltip="true" prop="bannerName" label="通知名称" />
      <el-table-column prop="imageUrl" label="banner图">
        <template slot-scope="scope">
          <el-image v-if="scope.row.imageUrl" style="width: 100px; height: 100px" :src="scope.row.imageUrl" /></template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="docUrl" label="说明文档">
        <template slot-scope="scope">
          <div v-if="scope.row.docContent">
            <el-button type="text" size="small" @click="upItem(scope.row)">更新</el-button>
            <el-button type="text" size="small" @click="deleDoc(scope.row)">删除</el-button>
          </div>
          <div v-else>
            <el-button type="text" size="small" @click="upItem(scope.row)">添加</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="createdAt" label="创建时间" />
      <el-table-column
        label="操作"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          <!-- <el-button type="text" size="small" @click="upItem(scope.row)">修改</el-button> -->
          <el-button type="text" size="small" @click="deleItem(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
    <!-- </el-col> -->
    <!-- </el-row> -->
  </div>
</template>

<script>
import crudHelp from '@/api/help'
import { editBanners } from '@/api/help'
import CRUD, { presenter, header, crud } from '@crud/crud'
// import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'
// import DateRangePicker from '@/components/DateRangePicker'
import { mapGetters } from 'vuex'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
  name: 'Paint',
  components: { pagination },
  cruds() {
    return CRUD({ title: '横幅', url: 'api/banner', crudMethod: { ...crudHelp }})
  },
  mixins: [presenter(), header(), crud()],
  // 数据字典
  dicts: ['user_status'],
  data() {
    return {
      ruleForm: {
        bannerName: '',
        docContent: '',
        imageUrl: ''
      },
      height: document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  computed: {
    ...mapGetters([
      'user',
      'baseApi'
    ])
  },
  created() {
  },
  mounted: function() {
    const that = this
    window.onresize = function temp() {
      that.height = document.documentElement.clientHeight - 180 + 'px;'
    }
  },
  methods: {
    deleItem(row) {
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await crudHelp.del([row.bannerId])
        this.crud.toQuery()
        this.$message({
          type: 'success',
          message: '已删除!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    deleDoc(row) {
      crudHelp.getBanners({
        bannerId: row.bannerId
      }).then((res) => {
        this.ruleForm = res.content[0]
        this.ruleForm.docContent = ''
        editBanners(this.ruleForm).then(() => {
          this.$message({
            type: 'success',
            message: '已删除!'
          })
          this.crud.toQuery()
        })
      })
    },
    upItem(row) {
      this.$router.push({
        path: '/help/paint/addPaint',
        query: {
          bannerId: row.bannerId }
      })
    },
    addPaint() {
      this.$router.push({
        path: '/help/paint/addPaint'
      })
    }
  }
}
</script>

        <style rel="stylesheet/scss" lang="scss" scoped>
          .head-container {
            display: flex;
            justify-content: space-between;
            .btnContain {
              ::v-deep .el-button {
              background-color: rgba(236, 91, 91, 1);
              color: #fff;
              border: 0;
            }
            }
            // .imgCon {
            //   img {
            //     width: 100px;
            //   height: 100px;
            //   }

            // }
          }

        </style>

